Skip to main content

Pure Function

A pure function is a function that always:

  1. Produces the same output for the same input (deterministic behavior)
  2. Has no side effects

Rules of a Pure Function

RuleDescription
1. Same input → same outputFunction must always return the same result for given arguments
2. No side effectsIt should not modify any external variable, object, DOM, or database
3. No reliance on external mutable stateShouldn’t depend on changing global variables or random values
  • Math.random() impure function.